package com.probox.common.entity.domain.order;

import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.util.List;

import com.probox.common.core.enums.*;
import com.probox.common.core.utils.StringUtils;
import com.probox.common.core.utils.money.PriceFormatUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import com.baomidou.mybatisplus.annotation.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.probox.common.core.annotation.Excel;

/**
 * 订单售后对象 order_post_sale
 *
 * @author hds
 * @date 2021-06-07
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("order_post_sale")
@ApiModel(description="订单售后")
public class OrderPostSale implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 售后ID
     */
    //默认主键自增
    @TableId(value = "SERVICE_UID", type = IdType.AUTO)
    @ApiModelProperty(value = "售后ID")
    private Long serviceUid;
    /** 平台ID */
    @Excel(name = "平台ID")
    @ApiModelProperty(value = "平台ID(平台ID)")
    private Long platformUid;

    /** 订单ID */
    @Excel(name = "订单ID")
    @ApiModelProperty(value = "订单ID(订单ID)")
    private Long orderUid;

    /** 订单编号 */
    @Excel(name = "订单编号")
    @ApiModelProperty(value = "订单编号(订单编号)")
    private String orderNo;

    /** 订单明细 */
    @Excel(name = "订单明细")
    @ApiModelProperty(value = "订单明细(订单明细)")
    private Long itemUid;

    /** 供应商ID */
    @Excel(name = "供应商ID")
    @ApiModelProperty(value = "供应商ID(供应商ID)")
    private Long supplierUid;

    /** 供应商名称 */
    @Excel(name = "供应商名称")
    @ApiModelProperty(value = "供应商名称(供应商名称)")
    private String supplierName;

    /** 售后类型(refund 退款,return 退款退货,change更换) */
    @Excel(name = "售后类型(refund 退款,return 退款退货,change更换)")
    @ApiModelProperty(value = "售后类型(refund 退款,return 退款退货,change更换)")
    private String serviceType;

    /** 售后原因 根据类型选择 */
    @Excel(name = "售后原因 根据类型选择")
    @ApiModelProperty(value = "售后原因 根据类型选择 ")
    private String serviceReason;

    /** 售货数量 */
    @Excel(name = "售货数量")
    @ApiModelProperty(value = "售货数量(售货数量)")
    private Integer serviceNumber;

    /** 售货金额 */
    @Excel(name = "售货金额")
    @ApiModelProperty(value = "售货金额(售货金额)")
    private Long serviceAmount;

    /** 余额退款（后台可修改，现金退款+余额退款之和不能大于售后金额） */
    @Excel(name = "余额退款" , readConverterExp = "后台可修改，现金退款+余额退款之和不能大于售后金额")
    @ApiModelProperty(value = "余额退款(后台可修改，现金退款+余额退款之和不能大于售后金额)")
    private Long serviceBalance;

    /** 现金退款（后台可修改，现金退款+余额退款之和不能大于售后金额） */
    @Excel(name = "现金退款" , readConverterExp = "后台可修改，现金退款+余额退款之和不能大于售后金额")
    @ApiModelProperty(value = "现金退款(后台可修改，现金退款+余额退款之和不能大于售后金额)")
    private Long serviceCash;

    /** 图片凭证 */
    @Excel(name = "图片凭证")
    @ApiModelProperty(value = "图片凭证(图片凭证)")
    private String proofImages;

    /** 凭证描述 */
    @Excel(name = "凭证描述")
    @ApiModelProperty(value = "凭证描述(凭证描述)")
    private String proofDesc;

    /** 售后状态(0取消售后,1申请待处理,2处理中,3拒绝售后,4同意售后,,5售后完成) */
    @Excel(name = "售后状态(0取消售后,1申请待处理,2处理中,3拒绝售后,4同意售后,,5售后完成)")
    @ApiModelProperty(value = "售后状态(0取消售后,1申请待处理,2处理中,3拒绝售后,4同意售后,,5售后完成)")
    private String dataStatus;

    /** 申请人ID */
    @Excel(name = "申请人ID")
    @ApiModelProperty(value = "申请人ID(申请人ID)")
    private Long applyUid;

    /**  申请人昵称 */
    @Excel(name = " 申请人昵称")
    @ApiModelProperty(value = " 申请人昵称( 申请人昵称)")
    private String applyNickName;

    /** 联系电话 */
    @Excel(name = "联系电话")
    @ApiModelProperty(value = "联系电话(联系电话)")
    private String applyPhone;

    /** 申请时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "申请时间" , width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "申请时间(申请时间)")
    private Date applyTime;

    /** 客户收货地址 */
    @Excel(name = "客户收货地址")
    @ApiModelProperty(value = "客户收货地址(客户收货地址)")
    private Long customerAddressUid;

    /** 商家收货地址 */
    @Excel(name = "商家收货地址")
    @ApiModelProperty(value = "商家收货地址(商家收货地址)")
    private Long supplierAddressUid;

    /** 修改人 */
    @Excel(name = "修改人")
    @ApiModelProperty(value = "修改人(修改人)")
    private Long updateUser;

    /** 修改人名称 */
    @Excel(name = "修改人名称")
    @ApiModelProperty(value = "修改人名称(修改人名称)")
    private String updateName;

    /** 修改时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "修改时间" , width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "修改时间(修改时间)")
    private Date updateTime;

    /** 处理备注 */
    @Excel(name = "处理备注")
    @ApiModelProperty(value = "处理备注(处理备注)")
    private String remark;

    @Excel(name = "快递单号(用户退换货)")
    @ApiModelProperty(value = "快递单号(用户退换货)")
    private String logisticsNo;

    @TableField(exist = false)
    public List<String> applyTimeArray;

    @TableField(exist = false)
    public OrderInfoItem item;

    public String getServiceAmountStr(){
        return PriceFormatUtil.format(serviceAmount);
    }

    public String getServiceBalanceStr(){
        return PriceFormatUtil.format(serviceBalance);
    }

    public String getServiceCashStr(){
        return PriceFormatUtil.format(serviceCash);
    }

    public String getServiceTypeName(){
        return ServiceTypeEnum.getNameByKey(serviceType);
    }

    public String getDataStatusName(){
        return ServiceStatusEnum.getNameByKey(dataStatus);
    }

    public String getReasonName(){
        if(ServiceTypeEnum.refund.getKey().equals(serviceType)){
            return ServiceRefundEnum.getNameByKey(serviceReason);
        }else if(ServiceTypeEnum.returnd.getKey().equals(serviceType)){
            return ServiceReturnEnum.getNameByKey(serviceReason);
        }else if(ServiceTypeEnum.change.getKey().equals(serviceType)){
            return ServiceChangeEnum.getNameByKey(serviceReason);
        }
        return "";
    }

    public String getProofImagesOne() {
        if(!StringUtils.isEmpty(proofImages)){
            String[] split = proofImages.split(",");
            return split[0];
        }
        return "";
    }

}
